package cn.baddonkey.superquery.controller;

import cn.baddonkey.superquery.request.ModuleAddRequest;
import cn.baddonkey.superquery.request.ModuleUpdateRequest;
import cn.baddonkey.superquery.response.CommonResult;
import cn.baddonkey.superquery.service.ModuleBaseInfoService;
import cn.baddonkey.superquery.vo.ModuleBaseInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.net.www.http.HttpClient;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

@RestController
@RequestMapping("/moduleBaseInfo")
public class ModuleBaseInfoController {

    @Autowired
    private ModuleBaseInfoService moduleBaseInfoService;

    @PostMapping("/list")
    public CommonResult<List<ModuleBaseInfoVo>> list() {
        List<ModuleBaseInfoVo> moduleBaseInfoVos = moduleBaseInfoService.listAll();
        return CommonResult.success(moduleBaseInfoVos);
    }

    @PostMapping("/add")
    public CommonResult<Void> add(@RequestBody @Validated ModuleAddRequest request) {
        moduleBaseInfoService.add(request);
        return CommonResult.success();
    }

    @PostMapping("/update")
    public CommonResult<Void> modify(@RequestBody @Validated ModuleUpdateRequest request) {
        moduleBaseInfoService.modify(request);
        return CommonResult.success();
    }

}
